package com.song.JavaThread_day04.ch4_6;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class Task  implements Callable<Result>{

	private String name;
	
	
	
	public Task(String name) {
		super();
		this.name = name;
	}



	@Override
	public Result call() throws Exception {
		System.out.printf(" %s : String \n",this.name);
		
		try {
			long duration =(long)(Math.random()*10);
			System.out.printf(" %s : waiting %d seconds for results \n",this.name ,duration);
			TimeUnit.SECONDS.sleep(duration);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int value =0;
		for(int i=0;i<5;i++)
			value+=(int)(Math.random()*100);
		Result result = new Result();
		result.setName(this.name);
		result.setValue(value);
		System.out.println(this.name +" : Ends");
		return result;
	}

}
